// 导入axios
import axios from 'axios'
import { useUserStore } from '@/stores/user'
// 创建 request 实例
const request = axios.create({
  // baseURL: 'http://192.168.1.45:8080'
  baseURL: 'http://localhost:8080'
  // baseURL: 'http://192.168.1.81:8080'
  //  baseURL: 'http://192.168.46.13:8080'
})

// 请求拦截器
request.interceptors.request.use(
  (config) => {
    const store = useUserStore()
    config.headers.satoken = store.token
    return config
  },
  (error) => Promise.reject(error)
)
// 响应拦截器
request.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => Promise.reject(error)
)

// 导出
export default request
